package cn.itcast.config;

import com.alibaba.druid.pool.DruidAbstractDataSource;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
@PropertySource("classpath:jdbc.properties")
public class Config {

    @Value("${jdbc.driver}")
    private String drive;

    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.user}")
    private String username;

    @Value("${jdbc.password}")
    private String password;

    @Bean
    public DataSource getds(){
        DruidAbstractDataSource ds=new DruidDataSource();
        ds.setDriverClassName(drive);
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        return ds;
    }

    @Autowired
    DataSource ds;
    @Bean
    public JdbcTemplate getJd(){

        JdbcTemplate jt=new JdbcTemplate(ds);
        return jt;
    }
}
